<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<script>
			// 基础方法
			// function isPrime(num) {
			//	if (num == 1) return false
			// 	if (num == 2) return true
			// 	let i = num - 1
			// 	while (--i > 1) {
			// 		if (num % i === 0) {
			// 			return false
			// 		}
			// 	}
			// 	return true
			// }

			// 高级算法
			function isPrime(num) {
				if (num == 1) return false
				let temp = parseInt(Math.sqrt(num))
				let i = 2
				while (i <= temp) {
					if (num % i === 0) {
						return false
					}
					i++
				}

				return true
			}
			function getNextPrim(num) {
				num++
				while (!isPrime(num)) {
					num++
				}
				return num
			}
			function getPrePrim(num) {
				num--
				while (!isPrime(num)) {
					num--
				}
				return num
			}
			console.log(getPrePrim(33))
			console.log(getNextPrim(33))
		</script>
	</body>
</html>
